home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / RCS / lstAppend.c,v < prev    next >
Encoding:
Text File  |  1992-05-19  |  2.5 KB  |  113 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     89.06.13.15.01.33;  author adam;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.6
  21. log
  22. @checked in with -k by kupfer at 92.05.18.17.32.32.
  23. @
  24. text
  25. @/*-
  26.  * LstAppend.c --
  27.  *    Add a new node with a new datum after an existing node
  28.  *
  29.  * Copyright (c) 1988 by University of California Regents
  30.  *
  31.  * Permission to use, copy, modify, and distribute this
  32.  * software and its documentation for any purpose and without
  33.  * fee is hereby granted, provided that the above copyright
  34.  * notice appears in all copies.  Neither the University of California nor
  35.  * Adam de Boor makes any representations about the suitability of this
  36.  * software for any purpose.  It is provided "as is" without
  37.  * express or implied warranty.
  38.  */
  39. #ifndef lint
  40. static char *rcsid =
  41. "$Id: lstAppend.c,v 1.6 89/06/13 15:01:33 adam Exp $ SPRITE (Berkeley)";
  42. #endif lint
  43.  
  44. #include    "lstInt.h"
  45.  
  46. /*-
  47.  *-----------------------------------------------------------------------
  48.  * Lst_Append --
  49.  *    Create a new node and add it to the given list after the given node.
  50.  *
  51.  * Results:
  52.  *    SUCCESS if all went well.
  53.  *
  54.  * Side Effects:
  55.  *    A new ListNode is created and linked in to the List. The lastPtr
  56.  *    field of the List will be altered if ln is the last node in the
  57.  *    list. lastPtr and firstPtr will alter if the list was empty and
  58.  *    ln was NILLNODE.
  59.  *
  60.  *-----------------------------------------------------------------------
  61.  */
  62. ReturnStatus
  63. Lst_Append (l, ln, d)
  64.     Lst          l;    /* affected list */
  65.     LstNode    ln;    /* node after which to append the datum */
  66.     ClientData    d;    /* said datum */
  67. {
  68.     register List     list;
  69.     register ListNode    lNode;
  70.     register ListNode    nLNode;
  71.     
  72.     if (LstValid (l) && (ln == NILLNODE && LstIsEmpty (l))) {
  73.     goto ok;
  74.     }
  75.     
  76.     if (!LstValid (l) || LstIsEmpty (l)  || ! LstNodeValid (ln, l)) {
  77.     return (FAILURE);
  78.     }
  79.     ok:
  80.     
  81.     list = (List)l;
  82.     lNode = (ListNode)ln;
  83.  
  84.     PAlloc (nLNode, ListNode);
  85.     nLNode->datum = d;
  86.     nLNode->useCount = nLNode->flags = 0;
  87.     
  88.     if (lNode == NilListNode) {
  89.     if (list->isCirc) {
  90.         nLNode->nextPtr = nLNode->prevPtr = nLNode;
  91.     } else {
  92.         nLNode->nextPtr = nLNode->prevPtr = NilListNode;
  93.     }
  94.     list->firstPtr = list->lastPtr = nLNode;
  95.     } else {
  96.     nLNode->prevPtr = lNode;
  97.     nLNode->nextPtr = lNode->nextPtr;
  98.     
  99.     lNode->nextPtr = nLNode;
  100.     if (nLNode->nextPtr != NilListNode) {
  101.         nLNode->nextPtr->prevPtr = nLNode;
  102.     }
  103.     
  104.     if (lNode == list->lastPtr) {
  105.         list->lastPtr = nLNode;
  106.     }
  107.     }
  108.     
  109.     return (SUCCESS);
  110. }
  111.  
  112. @
  113.